//
//  UIBarButtonItem+Extensions.swift
//  Swift微博
//
//  Created by 汪大强 on 2018/7/19.
//  Copyright © 2018年 汪大强. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 实例化 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title:      title
    ///   - fontSize:   fontSize, 默认 16 号
    ///   - target:     target
    ///   - action:     action
    ///   - isBackButton: 是否是返回按钮，如果是加上箭头
    convenience init(title:String, fontSize:CGFloat = 16, target:AnyObject, action: Selector, isBackButton:Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBackButton {
            let imageName = "返回"
            btn.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named: imageName + "点击后"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        
        // 实例化 UIBarButtonItem
        self.init(customView:btn)
    }
}
